package main.java.dao.impl;

import main.java.dao.BaseDAO;
import main.java.dao.DoctorDao;
import main.java.polo.Doctor;

import java.util.Collections;
import java.util.List;




public class DoctorDaoImpl extends BaseDAO implements DoctorDao {

    @Override
    public List<Doctor> selectAll() {
        try {
            String sql = "select dr_id drId ,dr_name drName ,dr_time drTime ,dr_dept drDept from t_dr";
            return executeQuery(Doctor.class, sql,null);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<Doctor> selectByDept(String DrDept) {
        try {
            String sql = "select dr_id drId ,dr_name drName ,dr_time drTime from t_dr where dr_dept = ?";
            return executeQuery(Doctor.class, sql,DrDept);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }



    @Override
    public int insert(Doctor doctor) {
        try {
            String sql = "insert into t_dr (dr_name, dr_time, dr_Dept) values (?,?,?)";
            return executeUpdate(sql,doctor.getDrName(),doctor.getDrTime(),doctor.getDrDept());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int delete(Integer DrId) {
        try {
            String sql = "delete from t_dr where dr_id = ?";
            return executeUpdate(sql,DrId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int update(Doctor doctor) {
        try {
            String sql = "update t_dr set dr_name = ?, dr_time = ?, dr_dept = ? where dr_id = ?";
            return executeUpdate(sql,doctor.getDrName(),doctor.getDrTime(),doctor.getDrDept(),doctor.getDrId());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
